<?php

namespace app\common\controller;

use app\admin\model\User;
use app\BaseController;
use think\facade\Cache;

class ApiController extends BaseController
{
    protected $uid;
    protected $tid;
    protected function initialize()
    {
        parent::initialize();
        $token=$this->request->header('token');
        $tid=$this->request->header('tid');
        $requestUrl=$this->request->controller().'/'.$this->request->action();
        $authUrl=['User/getSelfInfo','User/saveUser','Upload/upload'];
        if(in_array($requestUrl,$authUrl)&&empty($token)){
            return json(['code'=>0,'msg'=>'未登录！']);
        }
        if(!empty($token)) {
            $cache = Cache::get($token);
            $this->uid = $cache['uid'];
        }
        $this->tid=empty($tid)?null:$tid;
    }
}